﻿
CREATE PROCEDURE [dbo].[proc_Order_GetItem]
	(
		@OId uniqueidentifier
	)
AS
	Select [Order].Id
		,OId
		,IsNull(OrderId,'') As OrderId
		,CusId
		,IsNull((Select WebAddress From Customer Where Customer.CustomerId=CusId),'') As WebAddress
		,CusName
		,IsNull(CusName_BD,'') As CusName_BD
		,CusPerson
		,CusPersonTel
		,CusDescription
		,CusEstimate
		,[Order].TypeId
		,TypeName
		,WayId
		,WayName
		,ProcessId
		,ProcessName
		,Case When WayId=6 Then	Salesman + ' (InSide：' + IsNull((Select Top 1 EName From Employee Where UserName In(Select Top 1 InSide From InOutSide Where InOutSide.CusId=[Order].CusId Order By Id Desc)),'') + ')' Else Salesman End As Salesman
--		,Salesman
		,SalesmanAccount
		,TradeDate
		,[Order].CreateDate
		,IsNull(shjbh,'') As shjbh
		,IsNull(htbh,'') As htbh
		,YingShouPrice
		,IsNull(ShiShouPrice,0) As ShiShouPrice
		,Discount
		,PaymentTypeId
		,PaymentType
		,BankId
		,Bank
		,PaymentDescription
		,OtherDescription + '||' + IsNull((Select [Address] From Customer Where Customer.CustomerId=CusId),'') As OtherDescription
		,DepId
		,[Order].CompanyId
		,[Order].StateId
		,IsNull(TrackKfName,'') As TrackKfName
		,GenJinKfName
		,IsNull([Order].AuditPerson,'') As AuditPerson
		,IsNull(AuditDate,'1900-01-01') As AuditDate
		,IsNull((Select Title From Order_State Where Id=[Order].StateId),'---') As StateName
		,NOE_Flag,isnull(trackBDName,'') as trackBDName,c.RegTime,c.RegCapital,c.Employees
		,(Select Title from Customer_Employees e where e.id=c.Employees) EmployeesName,c.Introduction,p.Age,p.Weixin
From [Order] left join Customer c on [Order].CusId=c.CustomerId 
		 left join ContactPerson p on [Order].CusId=p.CustomerId and p.IsMain=1
Where OId=@OId